  var geocoder;
  var map;
  var myLatlng;
  var myAddress;
  var marker;
  var infowindow;
  var contentString;

  function initialize() {
	  
    myLatlng = new google.maps.LatLng(-23.547778,-46.635833);
    myAddress = "São Paulo"	
	
	
    var myOptions = {
      zoom: 13,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
	
    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
		
 	marker = new google.maps.Marker({
			draggable:true,
            map: map,
            position: myLatlng,
			animation: google.maps.Animation.DROP,
			title:"Problema Encontrado!"

  });
  

  geocoder = new google.maps.Geocoder();
  
  codeAddress();  
  
  }
  
  
  function codeAddress() {
	  
	var address = document.getElementById("txtEndereco").value;
	
    geocoder.geocode( { 'address': address, 'region': 'BR'}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
		  
		marker.setMap(null);
        map.setCenter(results[0].geometry.location);
		
		myLatlng = results[0].geometry.location;
		myAddress = results[0].formatted_address;			
		
        marker = new google.maps.Marker({
			draggable:true,
            map: map,
            position: myLatlng,
			animation: google.maps.Animation.DROP,
			title:"Problema Social Encontrado!"
        });			
		
	
		
		document.getElementById('txtEndereco').value = myAddress;
		document.getElementById('txtCoordenada').value = myLatlng;
		
					
    google.maps.event.addListener(marker, 'drag', function () {
		
    geocoder.geocode({ 'latLng': marker.getPosition() }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {  
					
		myLatlng = results[0].geometry.location;
		myAddress = results[0].formatted_address;		
		
		document.getElementById('txtEndereco').value = myAddress;
		document.getElementById('txtCoordenada').value = myLatlng;				

                }
            }
        });
    });

		
		
/*
		contentString = '<br/> Alerta!<br/> Problema Social encontrado em ' + address + '<br/>' + myLatlng ; 

  	infowindow = new google.maps.InfoWindow({
		content: contentString
	});	
  
  google.maps.event.addListener(marker, 'click', function() {
	  infowindow.open(map,marker);
	});			
		*/ 			
				
      } else {
        alert("Ops! Endereço Não Encontrado.  ");		
      }
		  
    });
	
	
  }

  